﻿#ifndef COMMONTYPE_H_
#define COMMONTYPE_H_

#include <iostream>
#include <vector>
#include <map>

namespace zl
{

/// \brief 错误码
enum EResult
{
    EResult_Success = 0x00,
	EResult_Failed,

	EResult_OpenFileFailed,
	EResult_WriteFileFailed,
	EResult_ParseJsonFailed,

	EResult_FacialNotInitialized,
	EResult_FacialCreateFailed,
	EResult_FacialInitChannelFailed,
	EResult_FacialDetectFailed,
	EResult_FacialExtractFailed,
	EResult_FacialWrongParams,
	EResult_FacialPreserveFailed,
	EResult_FacialRetriveFailed,
	EResult_FacialCameraConnectFailed,
	EResult_FacialYMPCConnectFailed,
	EResult_FacialInitCameraFailed,

	EResult_OrderNotFound,

	EResult_CabinetNotInitialized,
	EResult_InvalidLockerNo,
	EResult_InvalidCard,

	EResult_Unknown = 0xFF
};

/// \brief 用户状态
enum EUserStatus
{
    EUserStatus_Success = 0x00,             ///< 登陆成功
    EUserStatus_UnRegister = 0x01,          ///< 未注册
    EUserStatus_RequiredDeposit = 0x02,     ///<
    EUserStatus_Arrears = 0x03,             ///<
    EUserStatus_Abnormal = 0x04,            ///< 已有订单
    EUserStatus_NoPhone = 0x05,             ///< 没有手机号码
    EUserStatus_UnConfirmed = 0x06,         ///< 未确认
    EUserStatus_QRCodeNotScaned = 0x09      ///< 未扫描二维码
};

/// \brief 格口类型定义
enum ELockerType
{
    ELockerType_Small = 0x01,       ///< S
    ELockerType_Medium = 0x02,      ///< M
    ELockerType_Large = 0x03,       ///< L
    ELockerType_ExtraLarge = 0x04,  ///< E

    ELockerType_Default = 0xFF      ///< F
};

/// \brief 格口状态
enum ELockerStatus
{
    ELockerStatus_Normal = 0x00,    ///< 可用状态
    ELockerStatus_Door = 0x01,      ///< 门开
    ELockerStatus_Item = 0x02,      ///< 有物品
    ELockerStatus_Error = 0x04,     ///< 格口出错
    ELockerStatus_Occupied = 0x08,  ///< 格口被占用
    ELockerStatus_Expired = 0x10,   ///< 格口超期
    ELockerStatus_Locked = 0x20,    ///< 格口被锁定

    ELockerStatus_ALL = 0xFFFFFFFF  ///< 异常状态
};

/// \brief 管理卡状态
enum ECardStatus
{
    ECardStatus_Locked = 0x00,      ///< 锁定状态,不可用
    ECardStatus_Root = 0x01,        ///< 超级管理员权限
    ECardStatus_Normal = 0x02,      ///< 正常状态
    ECardStatus_Error = 0xFF        ///< 错误状态
};

/// \brief 订单状态
enum EOrderStatus
{
    EOrderStatus_Prepared = 0x01,           ///< 创建订单
    EOrderStatus_Using = 0x02,              ///< 正在使用
    EOrderStatus_Finished = 0x03,           ///< 结束使用
    EOrderStatus_Completed = 0x04,          ///< 订单完成
    EOrderStatus_Error = 0x05,              ///< 订单出错
    EOrderStatus_Expired = 0x06,            ///< 订单超期
    EOrderStatus_Locked = 0x07,             ///< 订单锁定
    EOrderStatus_Canceled = 0x08,           ///< 订单被取消
    EOrderStatus_ManualFinished = 0x09      ///< 订单在终端上被人工取消
};

// platform
typedef struct {
    std::string						remote_addr;		///< 管理台通信地址
    int32_t							remote_port;		///< 管理台通信端口
    int32_t							local_port;         ///< 本地通信端口

    std::string                     corp_id;            ///< 支付服务器参数
    std::string                     corp_name;          ///< 支付服务器参数
    std::string                     site_id;            ///< 支付服务器参数
    std::string                     site_name;          ///< 支付服务器参数
    std::string                     auth_id;            ///< 支付服务器参数
    std::string                     auth_name;          ///< 支付服务器参数
    std::string                     payplat_uri;        ///< 支付服务器接口地址
}PlatformConfig;

/// \brief 终端配置信息
typedef struct
{
    std::string id;                 ///< 终端ID
    std::string name;               ///< 终端名

    int32_t tag_number;             ///< 当前柜子的起始标签号
    std::string validator_com;      ///< itl纸币器串口号
    int32_t validator_baud;         ///< itl纸币器波特率
    int32_t validator_type;         ///< 纸币器类型（0：ITL，1：MEI）
} CabinetInfo;

// 中间件配置信息
typedef struct  {
    int32_t index;
    int32_t count;

    uint8_t col;
    int32_t protocol_type;
    struct {
        int32_t type;
        int32_t is_shared;
        int32_t localport;
        std::string remoteaddr;
        int32_t remoteport;

        std::string com;
        int32_t baud_rate;
        int32_t flow_control;
        int32_t parity;
        int32_t stop_bits;
        int32_t character_size;

        int32_t timeout_conn;
        int32_t timeout_read;
        int32_t timeout_write;
    }   datalinkopt;
}DoorControlBoard;

typedef struct {
    int32_t index;
    std::string typestr;
} Layout;
using LockerLayout = std::vector<Layout>;

typedef struct
{
    std::vector<DoorControlBoard> dcb_list;
    LockerLayout layout_list;
} ZLBaseConfig;

// timeout itl
typedef struct {
    int32_t							status_itl;
    int32_t							heartbeat_itl;

    int32_t							page_deposit_selectsize;
    int32_t							page_deposit_setno;
    int32_t							page_deposit_setpwd;
    int32_t							page_deposit_open;
    int32_t							page_fetch_authpwd;
    int32_t							page_fetch_open;
    int32_t							page_paytype;
    int32_t							page_payinfo;
} TimeoutItl;

struct PaymentConf
{
    int32_t enable_alipay;                  ///< 是否启用支付宝支付（1:启用，0:不启用）
    int32_t enable_wechatpay;               ///< 是否启用微信支付（1:启用，0:不启用）
    int32_t enable_cash;                    ///< 是否启用现金支付（1:启用，0:不启用）
    int32_t enable_onecode;                 ///< 是否启用OneCode（1:启用，0:不启用）
    int32_t payment_small;
    int32_t payment_medium;
    int32_t payment_large;
    int32_t payment_extra_large;
};

typedef struct {
    CabinetInfo						cabinet;
    PlatformConfig					server;
    TimeoutItl						timeout;
    PaymentConf                     payment;
}AppConfig;

// locker
typedef struct Locker
{
    std::string cabinet_no;         ///< 柜号
    int32_t boxno;                  ///< 箱号
    int32_t type;                   ///< 类型
    int32_t status;                 ///< 状态
    int32_t pcbno;                  ///< 开门板板号
    int32_t index;                  ///< 序号
} Locker;
typedef std::vector<Locker> LockerVec;

// manager card
typedef struct ManagerCard
{
	std::string cardno;
	int32_t status;
} ManagerCard;
typedef std::vector<ManagerCard> ManagerCardVec;

/// \brief 订单信息
typedef struct Order
{
    std::string order_id;       ///< 订单ID
    int32_t status;             ///< 状态
    std::string begin_time;     ///< 开始时间
    std::string end_time;       ///< 结束时间
    std::string exp_time;       ///< 超期费用
    std::string update_time;    ///< 状态更新时间
    std::string cabinet_no;     ///< 终端编号
    int32_t box_no;             ///< 箱号
    int32_t box_type;           ///< 箱子类型
    std::string user_id;        ///< 身份ID
    std::string user_code;      ///< 身份码
    int32_t confirmed;          ///< 是否确认（0x01: 存物未确认，0x02：取物未确认）
    std::string fee;            ///< 支付的费用
    std::string facial_data;    ///< 人脸特征信息
    int32_t     facial_flag;    ///< 是否录入人脸信息
} Order;
typedef std::vector<Order> OrderVec;

/// \brief Operator Log
typedef struct OperLog
{
    std::string log_id;
    std::string cabinet_no;
    int32_t box_no;
    std::string action;             ///< 动作 存物/取物/中途开箱
    std::string type;               ///< 操作者类型
    std::string account;            ///< 操作者账号
    std::string time;
    int32_t confirmed;
} OperLog;
typedef std::vector<OperLog> OperLogVec;

/// \brief 支付详情
struct PaidDetail
{
    std::string order_id;       ///< 订单号
    std::string cabinet_id;     ///< 终端编号
    int32_t box_id;             ///< 格口号
    int32_t fee_total;          ///< 应付金额
    int32_t fee_paid;           ///< 已付金额
    int32_t confirmed;
    std::string usestate;       ///< 分配状态 (1:分配成功,0:分配失败)
    std::string pay_time;       ///< 支付时间
    std::string pay_mode;       ///< 支付方式 (0:现金,1:微信,2:支付宝)
    std::string pay_order_id;   ///< 支付记录订单号
    std::string pay_trade_no;   ///< 支付交易号
    std::string pay_prepay_id;  ///< 支付单号（当启用一码清时需要此参数）
};

} // namespace zl
#endif // COMMONTYPE_H_
